/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import SQLServer.connectSQLServer;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.ejb.Stateless;

/**
 *
 * @author Betty
 */
@Stateless
public class RequestXML {

    private connectSQLServer con;
    private ResultSet rs;
    private String xml, styleSheet;
    
    public RequestXML()
    {
        
    }
       
    public String[] getXmlData()   
    {
        con = new connectSQLServer();
        con.Connect();
        rs = con.executeProc("{call dbo.javaXmlTest2}");
        String[] mValues = new String[2];
        
        if(rs != null)
        {
            try
            {
                while(rs.next())
                {
                    xml = rs.getString(1);
                    mValues[0] = xml;
                    styleSheet = rs.getString(2);
                    mValues[1] = styleSheet;
                    rs.close();
                    //xml = "<h2>DPCore WIP Tracker</h2><br></br><table border=\"1\"><tr><th></th><th></th><th></th><th></th><th>Leadtime from Op ---&gt;</th><th bgcolor=\"#6495ED\">-1</th><th bgcolor=\"#6495ED\">0.0000</th><th bgcolor=\"#6495ED\">0.0000</th><th bgcolor=\"#6495ED\">2.0000</th><th bgcolor=\"#6495ED\">2.0000</th><th bgcolor=\"#6495ED\">2.0000</th><th bgcolor=\"#6495ED\">6.0000</th><th bgcolor=\"#6495ED\">7.0000</th><th bgcolor=\"#6495ED\">7.0000</th><th bgcolor=\"#6495ED\">7.0000</th><th bgcolor=\"#6495ED\">7.0000</th><th bgcolor=\"#6495ED\">11.0000</th><th bgcolor=\"#6495ED\">12.0000</th><th bgcolor=\"#6495ED\">14.0000</th><th bgcolor=\"#6495ED\">14.0000</th><th bgcolor=\"#6495ED\">15.0000</th><th bgcolor=\"#6495ED\">16.0000</th><th bgcolor=\"#6495ED\">21.0000</th></tr><tr><th></th><th></th><th></th><th></th><th>Progressive Yield ---&gt;</th><th bgcolor=\"Orange\">1.00</th><th bgcolor=\"Orange\">1.00000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th><th bgcolor=\"Orange\">0.80000</th></tr><tr bgcolor=\"#9acd32\"><th>StockCode</th><th>Sales order</th><th>Order Qty</th><th>Gross Qty</th><th>Ship date</th><th>F Goods</th><th>NC0001</th><th>FS0002</th><th>PI0003</th><th>XR0009</th><th>XR0008</th><th>XR0022</th><th>XR0005</th><th>BM0006</th><th>BM0005</th><th>HT0006</th><th>HT0009</th><th>HT0004</th><th>GG0001</th><th>BM0001</th><th>GR0001</th><th>HP0002</th><th>HP0001</th><th>Best ship date</th><th>Latest launch date</th></tr><tr><td>030K238</td><td>016690</td><td>80.000</td><td>80</td><td>2012-03-23</td><td bgcolor=\"Red\">80</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>11/06/2012 19:21:05</td><td></td></tr><tr><td>030K238</td><td>016691</td><td>80.000</td><td>94</td><td>2012-03-30</td><td bgcolor=\"Red\">3</td><td bgcolor=\"Red\">18</td><td bgcolor=\"Red\">37</td><td bgcolor=\"Red\">2</td><td bgcolor=\"Red\">9</td><td bgcolor=\"Red\">2</td><td bgcolor=\"Red\">5</td><td bgcolor=\"Red\">18</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>19/06/2012 19:21:06</td><td></td></tr><tr><td>030K238</td><td>016716</td><td>80.000</td><td>100</td><td>2012-04-13</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td bgcolor=\"Red\">10</td><td bgcolor=\"Red\">2</td><td bgcolor=\"Red\">50</td><td bgcolor=\"Red\">38</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>19/06/2012 19:21:06</td><td></td></tr><tr><td>030K238</td><td>016717</td><td>80.000</td><td>100</td><td>2012-04-13</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td bgcolor=\"Red\">22</td><td bgcolor=\"Red\">7</td><td bgcolor=\"Red\">13</td><td bgcolor=\"Red\">3</td><td bgcolor=\"Red\">8</td><td bgcolor=\"Red\">1</td><td bgcolor=\"Red\">23</td><td bgcolor=\"Red\">23</td><td>03/07/2012 19:21:06</td><td></td></tr><tr><td>030K238</td><td>016718</td><td>80.000</td><td>100</td><td>2012-04-20</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td bgcolor=\"Red\">100</td><td>03/07/2012 19:21:06</td><td></td></tr></table>";
                    return mValues;
                }
            }catch(SQLException ex)
            {
                mValues[0] = "Error: " + ex.getMessage() + 
                      ", State:  " + ex.getSQLState();
                styleSheet = null;
            }
        }else
        {
           mValues[0] = "no records retruned.";
           styleSheet = null;
        }
        return mValues;
   }
    
}
